/*
 * @Description: 
 * @Author: wangqi
 * @Date: 2021-04-17 12:05:11
 * @LastEditTime: 2021-04-17 19:41:54
 */
class SyncBailHook {
    constructor(args) {
        this.hooks = [];
    }

    tap(name, task) {
        this.hooks.push(task);
    }

    call(...res) {
        // 当前这个函数的返回值
        let ret;
        // 当前要执行的第一个函数
        let index = 0;

        do {
            ret = this.hooks[index++](...res);
            // console.log(ret)
        } while (!ret && index < this.hooks.length);
    }

}

let syncbailhook = new SyncBailHook(['name', 'age']);
syncbailhook.tap('node', (name, age) => {
    console.log('node', name, age);
    // return '不往下执行了'
});

syncbailhook.tap('vue', (name, age) => {
    console.log('vue', name, age)
    return '不往下执行了'
});

syncbailhook.tap('react', (name, age) => {
    console.log('react', name, age)
});

syncbailhook.call('wq', 12);


